<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>图书管理系统</title>
  <!-- Custom CSS -->
  <style>
    body {
      background-color: #f8f9fa;
      font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    }
    
    h1 {
      color: #2c3e50;
      font-weight: 600;
      border-bottom: 2px solid #3498db;
      padding-bottom: 0.5rem;
      margin-bottom: 1.5rem;
    }
    
    .table {
      margin-top: 1rem;
      background-color: white;
      box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.05);
      border-radius: 0.5rem;
      overflow: hidden;
      text-align: center;
    }
    
    .table th {
      background-color: #3498db;
      color: white;
      font-weight: 500;
      width: 100px;
    }

    .empty-state {
      margin-top: 1rem;
      text-align: center;
      padding: 2rem;
      background-color: white;
      border-radius: 0.5rem;
      box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.05);
    }
    
    .empty-state .icon {
      font-size: 3rem;
      color: #adb5bd;
      margin-bottom: 1rem;
    }
  </style>
</head>
<body>
  <div>
    <h1>📚 图书管理系统</h1>
    <button type="submit"><a href="/books/new">添加图书</a></button>
    
    <% if (books.length === 0) { %>
      <div class="empty-state">
        <div class="icon">📭</div>
        <h3>暂无图书数据</h3>
        <p>点击上方按钮添加第一本图书</p>
      </div>
    <% } else { %>
      <div>
        <table class="table">
          <thead>
            <tr>
              <th>书名</th>
              <th>作者</th>
              <th>出版社</th>
              <th>价格</th>
              <th colspan="2">操作</th>
            </tr>
          </thead>
          <tbody>
            <% books.forEach(book => { %>
              <tr>
                <td><%= book.name %></td>
                <td><%= book.author %></td>
                <td><%= book.press %></td>
                <td>¥<%= book.price.toFixed(2) %></td>
                <td>
                  <a href="/books/<%= book._id %>/edit">编辑</a>
                </td>
                <td>
                  <form action="/books/<%= book._id %>?_method=DELETE" method="POST">
                    <button type="submit">删除</button>
                  </form>
                </td>
              </tr>
            <% }) %>
          </tbody>
        </table>
      </div>
    <% } %>
  </div>
</body>
</html>
